package com.yifushidai.service.impl;

import com.yifushidai.entity.IcBind;
import com.yifushidai.service.IcBindService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

@Service
public class IcBindServiceImpl extends BaseService<IcBind> implements IcBindService {

    @Override
    public List<IcBind> queryListByMac(String mac) {
        // 创建Example
        Example example = new Example(IcBind.class);
        example.setOrderByClause("ic_type ASC");

        // 创建Criteria 添加条件
        Example.Criteria criteria = example.and();
        criteria.andEqualTo("mac", mac);

//        PageHelper.startPage(1, 10);
        return selectByExample(example);
    }

    @Override
    public List<IcBind> selectByMacAndIcType(IcBind record) {
        // 创建Example
        Example example = new Example(IcBind.class);

        // 创建Criteria 添加条件
        Example.Criteria criteria = example.and();
        criteria.andEqualTo("mac", record.getMac());
        criteria.andEqualTo("icType", record.getIcType());

        return selectByExample(example);
    }

    @Override
    public List<IcBind> selectByMacAndIcNo(IcBind record) {
        // 创建Example
        Example example = new Example(IcBind.class);

        // 创建Criteria 添加条件
        Example.Criteria criteria = example.and();
        criteria.andEqualTo("mac", record.getMac());
        criteria.andEqualTo("icNo", record.getIcNo());

        return selectByExample(example);
    }

    @Override
    public int deleteByMac(String mac) {
        // 创建Example
        Example example = new Example(IcBind.class);

        // 创建Criteria 添加条件
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("mac", mac);

        return deleteByExample(example);
    }

    @Override
    public int deleteByExpire() {
        // 创建Example
        Example example = new Example(IcBind.class);

        // 创建Criteria 添加条件
        Example.Criteria criteria = example.createCriteria();
        criteria.andLessThanOrEqualTo("expireDate", new Date());

        return deleteByExample(example);
    }
}
